package ua.at.tsvetkov.samizdat.services;

import ua.at.tsvetkov.samizdat.Const;
import ua.at.tsvetkov.samizdat.R;
import ua.at.tsvetkov.samizdat.data.AsyncTaskBooks;
import ua.at.tsvetkov.util.Log;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;

public class SrvBooks extends Service {

	private IBinder	binder;

	public class LocalBinder extends Binder {
		SrvBooks getService() {
			return SrvBooks.this;
		}
	}

	@Override
	public IBinder onBind(Intent intent) {
		Log.v(getString(R.string.SRV_BOOKS_BINDED));
		return binder;
	}

	@Override
	public void onCreate() {
		binder = new LocalBinder();
	}

	@Override
	public void onStart(Intent intent, int startid) {
		Log.v(getString(R.string.SRV_BOOKS_STARTED));
		Intent broadcastIntent = new Intent(Const.BROADCAST_MESSAGE).putExtra(Const.SERVICE_BOOKS_STARTED, Const.SERVICE_BOOKS_STARTED);
		sendBroadcast(broadcastIntent);
		AsyncTaskBooks asyncTaskBooks = new AsyncTaskBooks(this);
		asyncTaskBooks.execute();
	}

	@Override
	public void onDestroy() {
		Log.v(getString(R.string.SRV_BOOKS_STOPED));
		Intent broadcastIntent = new Intent(Const.BROADCAST_MESSAGE).putExtra(Const.SERVICE_BOOKS_STOPED, Const.SERVICE_BOOKS_STOPED);
		sendBroadcast(broadcastIntent);
	}
}
